package db;

import java.sql.DriverManager;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class DBConnection {
	private Connection connection;
	private final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
	private String username = "gomarket", password = "gomarket2013";
	private static final String dbname = "jdbc:mysql://gomarketinstance.cnaln6jln0uu.eu-west-1.rds.amazonaws.com/mydb";

	public DBConnection(String userd, String passd) {
		this.password = passd;
		this.username = userd;
	}

	public DBConnection() {
	}

	public void connect() {
		try {
			Class.forName(JDBC_DRIVER);
			connection = (Connection) DriverManager.getConnection(dbname, username, password);
			System.out.println("Database connection established");
		} catch (Exception e) {
			System.out.println("Database connection not established");
		}
	}

	public void disconnect() {
		try {
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Connection getConnection() {
		return connection;
	}

}
